<template>
  <div class="recommendList">
    <!-- 右下推荐圈子 -->
    <div
      v-for="(item, index) in allcirclelist"
      :key="index"
      class="recommendItem"
    >
      <div class="recommend">
        <img
          :src="item.thumb"
          alt=""
          class="header-img"
          @click="gotoclicle(item)"
        />
        <div class="recommendInfo">
          <div class="name">{{ item.title }}</div>
          <div class="people">{{ item.member_num }}成员</div>
        </div>
      </div>
      <div class="follow" @click="handleFocus(item)">
        <span>{{ item.foucs == "0" ? "+加入" : "已加入" }}</span>
      </div>
    </div>
  </div>
</template>

<script>
import { allquanzi, clickFollowFriend } from "@/api/community";
export default {
  props: {
    allcirclelist: {
      type: Array,
      default: ()=> [],
    },
  },
  data() {
    return {
      focusqz: [],
      selectList: [],
    };
  },
  mounted() {
    this.getCircle();
  },
  methods: {
    // 跳转至对应圈子
    gotoclicle(item) {
      this.$store.commit("SET_PERLEFTMENUSHOW", false);
      this.$router.push({
        path: "/circle",
        query: {
          id: item.id,
        },
      }); // window.open(routeData.href, '_blank');
    },

    // 关注
    handleFocus(item) {
      this.clickFollowFriend(item);
    },
    clickFollowFriend(e) {
      clickFollowFriend({
        foucsid: e.id,
        mid: JSON.parse(localStorage.userInfo).id,
        type: e.foucs == 1 ? 0 : 1, // 0 取消， 1 关注
      }).then((res) => {
        if (res.code === 1) {
          this.$emit("upquanziList");
          this.getCircle();
        }
      });
    },
    getCircle() {
      allquanzi({
        mid: JSON.parse(localStorage.userInfo).id,
        page: 1,
        pagesize: 10,
      }).then((res) => {
        if (res.code == 1) {
          // console.log(res,'quanzi');
          for (let i = 0; i < 3; i++) {
            this.selectList.push(res.circledata[i]);
          }
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.recommendList {
  .recommendItem {
    width: 90%;
    margin: 0 auto;
    margin-top: 10px;
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid #eee;

    .recommend {
      display: flex;

      // justify-content: space-between;
      .recommendInfo {
        .name {
          font-weight: bold;
        }

        .people {
          color: #ccc;
          text-align: center;
          font-size: 8px;
          border-radius: 3px;
        }
      }

      .header-img {
        width: 40px;
        height: 40px;
        border-radius: 50%;
      }
    }

    .follow {
      width: 40px;
      height: 20px;
      line-height: 20px;
      text-align: center;
      color: #f00;
      margin-right: 20px;
      border-radius: 10px;
    }
  }
}
</style>
